package com.bdqn.intercepts;

import org.apache.commons.lang3.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginHandlerInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
       String loginAccount= (String) request.getSession().getAttribute("loginAccount");
       if (StringUtils.isBlank(loginAccount)){
           request.getSession().setAttribute("login_error","login.msg.nopower");
           response.sendRedirect("login.html");
           return false;
       }
        return true;
    }
}
